<style>
    .xxpayPopupDiv .layui-form-label {
        width:15% !important;
        margin-left:1%;
    }
    .xxpayPopupDiv .layui-input-inline {
        width: 33% !important;
    }
</style>
<div class="layui-fluid" id="LAY-app-message">
    <div class="layui-card">
        <div class="layui-tab layui-tab-brief">
            <div class="layui-tab-content">
                <div class="layui-form-item">
                    <blockquote class="layui-elem-quote" id="amountTip"></blockquote>
                </div>
                <div class="layui-tab-item layui-show">
                    <form class="layui-form center">
                        <div class="layui-form-item">
                            <label class="layui-form-label">商户ID</label>
                            <div class="layui-input-inline">
                                <input type="text" id="mchId" name="mchId" lay-verify="required" autocomplete="off" class="layui-input" disabled="disabled">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">充值金额(元)</label>
                            <div class="layui-input-inline">
                                <input type="text" required id="amount" name="amount"  lay-verify="required|number" placeholder="请输入金额" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">备注</label>
                            <div class="layui-input-inline">
                                <input type="text" id="remark" name="remark" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <!--<div class="layui-form-item">-->
                            <!--<label class="layui-form-label">超级密码</label>-->
                            <!--<div class="layui-input-inline">-->
                                <!--<input type="password" required  name="password"  lay-verify="required|pass" placeholder="请输入超级密码" autocomplete="off" class="layui-input pwd">-->
                            <!--</div>-->
                        <!--</div>-->
                        <div class="layui-form-item" style="margin-left: 20%">
                            <div class="layui-input-block">
                                <button type="button" lay-submit lay-filter="btnCredit" class="layui-btn layui-btn-normal">增加金额</button>
                            </div>
                        </div>
                    </form>
                </div>

            </div>
        </div>
    </div>
</div>

<script>
    layui.use(['form','util','admin'], function(){
       var form = layui.form
       ,$ = layui.$
       ,admin = layui.admin
       ,upload = layui.upload
       ,element = layui.element;

       element.render('breadcrumb', 'breadcrumb');//渲染导航信息

        var mchId = layui.view.getOpenParams('mchId');

        admin.req({
            type: 'get',
            url: layui.setter.baseUrl + '/account/get?mchId=' + mchId,
            error: function(err){
                layer.alert(err.msg,{title:'请求失败'})
            },
            success:function(res){
                if(res.code == 0 && res.data != null){
                    $('#mchId').val(res.data.mchId);
                    $('#amountTip').html(
                            "可用代付余额: <span style='color: green'>" + res.data.availableAgentpayBalance / 100 + "</span> 元 " +
                            "可用账户余额: <span style='color: green'>" + res.data.availableBalance / 100 + "</span> 元 "
                    );
                }
            }
        });

       form.on('submit(btnCredit)', function(data){
           var amount = $("#amount").val();
           layer.confirm('确定为商户充值代付金额(' + amount + "元)么?", function(index){
               var load = layer.msg('正在充值...', {
                   icon: 16
                   ,shade: 0.01
                   ,time: 9999999999
               });
               admin.securityReq({
                   type: 'post',
                   url: layui.setter.baseUrl + '/account/agentpay_recharge',
                   data: data.field,
                   success: function(res){
                       if(res.code == 0){
                           layer.alert("充值成功!", {title: "提示"}, function(index){
                               layer.closeAll();
                               layui.table.reload('tableReload'); //调用业务弹层外表格重新加载
                           })
                       }else {
                           layer.close(load);
                       }
                   },
                   complete: function () {
                       layer.close(load);
                   }
               });
           });
           return false;//阻止跳转
        });

        form.render();

    })
</script>